/*
 *
 *  Copyright (C) 2012-2024
 *  All rights reserved, Designed By 杭州连线客信息技术有限公司
 *  注意：
 *  本软件为杭州连线客信息技术有限公司开发研制，未经购买不得使用
 *  购买后可获得全部源代码（禁止转卖、分享、上传到码云、github等开源平台）
 *  一经发现盗用、分享等行为，将追究法律责任，后果自负
 *
 */

package com.lxk.oms.postorder.flow.craete;

import com.lxk.event.oms.enums.OrderEnums;
import com.lxk.oms.order.service.IOmsOrderService;
import com.yomahub.liteflow.annotation.LiteflowComponent;
import com.yomahub.liteflow.core.FlowExecutor;
import com.yomahub.liteflow.core.NodeComponent;
import com.yomahub.liteflow.log.LFLog;
import com.yomahub.liteflow.log.LFLoggerManager;
import lombok.AllArgsConstructor;
import org.dromara.common.core.exception.ServiceException;

import static com.lxk.oms.postorder.flow.craete.FlowPostOrderNodeConst.POST_ORDER_INT_NODE;

/**
 * 订单售后状态变更
 *
 * @author heyi
 * 2024/9/29
 */
@LiteflowComponent(value = POST_ORDER_INT_NODE)
@AllArgsConstructor
public class PostOrderIngNode extends NodeComponent {
    private final IOmsOrderService omsOrderService;
    private final LFLog log = LFLoggerManager.getLogger(FlowExecutor.class);

    @Override
    public void process() throws Exception {
        PostOrderCreateContext context = this.getContextBean(PostOrderCreateContext.class);
        Long orderId = context.getOmsOrder().getId();
        String orderNo = context.getOrderNo();
        Boolean success = omsOrderService.updateOrderPostStatus(orderId, OrderEnums.PostStatus.INIT_0, OrderEnums.PostStatus.ING_1);
        if (!success) {
            success = omsOrderService.updateOrderPostStatus(orderId, OrderEnums.PostStatus.PART_3, OrderEnums.PostStatus.ING_1);
        }
        if (!success) {
            log.error("正在进行售后:orderNo:{}", orderNo);
            throw new ServiceException("正在进行售后,请勿重复提交");
        }
    }
}
